package com.wanmait.myhouse.webController;

import com.wanmait.myhouse.dao.UserDAO;
import com.wanmait.myhouse.vo.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("web")
public class WebLoginController {
    @PostMapping("userLogin")
    @ResponseBody
    public String userLogin(User user, HttpSession session){
        //调用UserDAO中的方法
        UserDAO userDAO = new UserDAO();
        User user1 = userDAO.chashujv(user);
        //如果user1为空，表示在数据库中查不到信息
        if(user1 != null){
            session.setAttribute("user",user1);
            return "1";
        }else {
            return "0";
        }
    }

    @GetMapping("login")
    public String login (){
        return "web/login";
    }

}
